package com.dongdongshop.controller;


import com.dongdongshop.data.Result;
import com.dongdongshop.domain.rep.ItemCatReq;
import com.dongdongshop.domain.rep.SpecificationReq;
import com.dongdongshop.domain.res.ItemCatRes;
import com.dongdongshop.service.ItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RefreshScope
@RequestMapping("item")
@Api("东东商城商品类目管理")
public class ItemController {

    @Autowired
    private ItemService itemService;


    /**
     * 商品类目查询
     * @return
     */
    @GetMapping("queryTree")
    @ApiOperation("商品类目查询")
    public Result<List<ItemCatRes>> queryTree() {
        List<ItemCatRes> catResList =itemService.queryTree();
        return Result.success(catResList);
    }



    /**
     * 商品类目增加修改操作
     * @param itemCatReq
     * @return
     */
    @PutMapping("save")
    @ApiOperation("商品类目增加修改操作")
    public Result save(@RequestBody ItemCatReq itemCatReq) {
        itemService.save(itemCatReq);
        return Result.success();
    }


    /**
     * 商品类目删除操作
     * @param id
     * @return
     */
    @DeleteMapping("delete/{id}")
    @ApiOperation("规格删除操作")
    public Result delete(@PathVariable("id") Long id){
        itemService.delete(id);
        return Result.success();
    }

    @GetMapping("queryAll")
    public List<ItemCatRes> queryAll(){
        List<ItemCatRes> catResList= itemService.queryAll();
        return catResList;
    }
}
